<?php

namespace app\student\model;

use think\Db;

class teacherBaseModel
{

    public static function teacherBaseModel(array $where)
    {
        //select t.*,GROUP_CONCAT(c.name) as c_name from s_teacher t
        //LEFT JOIN s_teaching tea on tea.t_id = t.id
        //LEFT JOIN s_course c on c.id = tea.c_id
        //where t.id = 2
        //group by t.id
        $result = Db::table('s_teacher')->alias('t')->field('t.*,GROUP_CONCAT(c.name) as c_name')
                        ->leftJoin('s_teaching tea','tea.t_id = t.id')
                        ->leftJoin('s_course c','c.id = tea.c_id')
                        ->where($where)->select();
        return $result;
    }


    public static function selectStudentCourse(array $where)
    {
        //select s.*,cls.name as cls_name, c.name as c_name,c.id as c_id, t.id as t_id,r.achievement
        //from   s_teacher t
        //LEFT JOIN s_report  r on t.id = r.t_id
        //LEFT JOIN s_student s on s.id = r.s_id
        //LEFT JOIN s_classes cls on cls.id = r.cls_id
        //LEFT JOIN s_course c on c.id = r.c_id
        //where t.id = 3

       // var_dump($where);
        $result = Db::table('s_teacher')->alias('t')->field('s.*,cls.name as cls_name, c.name as c_name,c.id as c_id,t.id as t_id, r.achievement')
                        ->leftJoin('s_report r','t.id = r.t_id')
                        ->leftJoin('s_student s','s.id = r.s_id')
                        ->leftJoin('s_classes cls','cls.id = r.cls_id')
                        ->leftJoin('s_course c','c.id = r.c_id')
                        ->where($where)->select();
        return $result;
    }



    public static function achievement(array $where)
    {
        $achievement['achievement'] = $where['achievement'];
        unset($where['achievement']);
        //var_dump($where,$achievement);
        $result = Db::table('s_report')->where($where)->update($achievement);
        return $result;
    }




}